<?php
/**
 * 微信管理.
 * User: Administrator
 * Date: 2019/11/27 0027
 * Time: 13:32
 */

namespace app\admin\controller;


use service\LogService;
use service\WechatService;
use think\Db;

class Wechat extends BasicAdmin{

    //微信基础参数配置
    public function config(){
        if($this->request->isPost()){
            foreach ($this->request->post() as $key => $vo) {
                sysconf($key, $vo);
            }
            LogService::write('微信管理', '修改微信接口参数成功');
            $this->result(null,'200','数据修改成功！','json');
        }
        return $this->fetch('',['title' => '微信管理 > 微信接口配置']);
    }

    //微信商户参数配置(页面禁用，手动数据库中配置)
    public function configPay(){
        return $this->fetch('',['title' => '微信管理 > 微信支付配置']);
    }

    //显示手机预览
    public function review(){
        $get = $this->request->get();
        $content = str_replace("\n", "<br>", $this->request->get('content', '')); // 内容
        $type = $this->request->get('type', 'text'); // 类型
        $this->assign('type', $type);
        // 图文处理
        if ($type === 'news' && is_numeric($content) && !empty($content)) {
            $news = WechatService::getNewsById($content);
            $this->assign('articles', $news['articles']);
        }
        // 文章预览
        if ($type === 'article' && is_numeric($content) && !empty($content)) {
            $article = Db::name('WechatNewsArticle')->where('id', $content)->find();
            if (!empty($article['content_source_url'])) {
                $this->redirect($article['content_source_url']);
            }
            $this->assign('vo', $article);
        }
        $this->assign($get);
        $this->assign('content', $content);
        // 渲染模板并显示
        return view();
    }




}